<template>
    <view>
        <scroll-view :scroll-y="true" class="scroll-box" @scrolltolower="scroll_lower" lower-threshold="30">
            <view class="panel-item teamlist padding-horizontal-main padding-top-main">
                <view class="panel-content bg-white" v-if="data_list.length > 0">
                    <view class="tuan_li" v-for="(item, index) in data_list" :key="index">
						<view class="liright">
						    <view class="tinfo">
						        <block v-if="item.content.jiang_type == '3'">
						            <text v-if="item.is_use == '2'" class="v3" :decode="true">已兑换</text>
						            <text v-else class="v3" :decode="true">待下单</text>
						        </block>
								<block v-if="item.content.jiang_type == '2'">
								    <text v-if="item.is_use == '1'" class="v3" :decode="true">已到账</text>
								    <text v-else class="v3" :decode="true">处理中</text>
								</block>
						        <block v-if="item.content.jiang_type == '1' || item.content.jiang_type == '4'">
						            <text class="v3">已领取</text>
						        </block>
						        <block v-if="item.content.jiang_type == '0'">
						            <text class="v3">加油~</text>
						        </block>
						    </view>
						</view>
						
                        <block v-if="item.content.jiang_type == '1'">
                            <image :src="dazhuanpan_static_url+'mini/quan.png'" mode="aspectFit" />
                            <view class="whois">
                                <view class="t1">优惠券：1张（{{ item.content.jiang_value }}）</view>
                                <text>{{ item.add_time }}</text>
                            </view>
                        </block>

                        <block v-if="item.content.jiang_type == '2'">
                            <image :src="dazhuanpan_static_url+'mini/hongbao.png'" mode="aspectFit" />
                            <view class="whois">
                                <view class="t1">现金：{{ item.content.jiang_value }}{{currency_symbol_after}}
									<navigator v-if="item.is_use == 0" url="/pages/fcc/cashtoweixinuserplus/index/index" hover-class="none" class="gotodone">
									    （点击去领取）
									</navigator>
								</view>
                                <text>{{ item.add_time }}</text>
                            </view>
                        </block>

                        <block v-if="item.content.jiang_type == '3'">
                            <image :src="dazhuanpan_static_url+'mini/sp.png'" mode="aspectFit" />
                            <view class="whois">
                                <view class="t1">
                                    商品：1件（{{ item.content.jiang_value }}）
                                    <navigator v-if="item.is_use != '2'" :url="'/pages/goods-detail/goods-detail?goods_id=' + item.goods_id" hover-class="none" class="gotodone">
                                        （点击去下单）
                                    </navigator>
                                </view>
                                <text>{{ item.add_time }}</text>
                            </view>
                        </block>

                        <block v-if="item.content.jiang_type == '4'">
                            <image :src="dazhuanpan_static_url+'mini/jifen.png'" mode="aspectFit" />
                            <view class="whois">
                                <view class="t1">积分：{{ item.content.jiang_value }}</view>
                                <text>{{ item.add_time }}</text>
                            </view>
                        </block>

                        <block v-if="item.content.jiang_type == '0'">
                            <image :src="dazhuanpan_static_url+'mini/wu.png'" mode="aspectFit" />
                            <view class="whois">
                                <view class="t1">未中奖</view>
                                <text>{{ item.add_time }}</text>
                            </view>
                        </block>
                    </view>
                </view>
            </view>

            <!-- 结尾 -->
            <component-bottom-line :propStatus="data_bottom_line_status"></component-bottom-line>

            <view v-if="detail == null">
                <component-no-data :propStatus="data_list_loding_status" :propMsg="data_list_loding_msg"></component-no-data>
            </view>
        </scroll-view>
    </view>
</template>

<script>
import componentNoData from "@/components/no-data/no-data";
import componentBottomLine from "@/components/bottom-line/bottom-line";

const app = getApp();
var dazhuanpan_static_url = app.globalData.get_static_url('dazhuanpan', true);
export default {
	components: {
		componentNoData,
		componentBottomLine
	},
    data() {
        return {
            currency_symbol_after: app.globalData.data.currency_symbol_after || '元',
			dazhuanpan_static_url:dazhuanpan_static_url,
            data_list: [],
            data_page_total: 0,
            data_page: 1,
            params: null,
            post_data: {},
            data_list_loding_status: 1,
            data_list_loding_msg: {},
            data_bottom_line_status: false,
            first_data: [],
            data_total: '',
            detail: ''
        };
    },
    onLoad(params) {
        this.setData({
            params: params,
            post_data: params
        });
    },
    onShow() {
        app.globalData.page_event_onshow_handle();
		uni.setNavigationBarTitle({
			title: this.$t('fengcheche.dazhuanpan.jilu')
		});
        this.init();
    },
    // 下拉刷新
    onPullDownRefresh() {
        this.setData({
            data_page: 1
        });
        this.get_data_list(1);
    },
    methods: {
        init() {
            var user = app.globalData.get_user_info(this, 'init');
            if (user != false) {
                // 获取数据
                this.get_data_list();
            } else {
                this.setData({
                    data_list_loding_status: 0,
                    data_bottom_line_status: false
                });
            }
        },

        get_data_list(is_mandatory) {
            // 分页是否还有数据
            if ((is_mandatory || 0) == 0) {
                if (this.data_bottom_line_status == true) {
                    return false;
                }
            }

            var self = this;
            uni.showLoading({
                title: this.$t('common.loading_in_text'),
            });
            this.setData({
                data_list_loding_status: 1
            }); 

            var params = this.params;
            var post_data = this.post_data;
            post_data['page'] = this.data_page; // 获取数据

            uni.request({
                url: app.globalData.get_request_url('record', 'index', 'dazhuanpan'),
                method: 'POST',
                data: post_data,
                dataType: 'json',
                header: {
                    'content-type': 'application/x-www-form-urlencoded'
                },
                success: (res) => {
                    uni.hideLoading();
                    uni.stopPullDownRefresh();
                    console.log(res);

                    if (res.data.code == 0) {
                        if (res.data.data.data.length > 0) {
                            if (this.data_page <= 1) {
                                var temp_data_list = res.data.data.data;
                            } else {
                                var temp_data_list = this.data_list;
                                var temp_data = res.data.data.data;

                                for (var i in temp_data) {
                                    temp_data_list.push(temp_data[i]);
                                }
                            }

                            this.setData({
                                data_list: temp_data_list,
                                data_total: res.data.data.total,
                                data_page_total: res.data.data.page_total,
                                data_list_loding_status: 3,
                                data_page: this.data_page + 1
                            }); // 是否还有数据

                            if (this.data_page > 1 && this.data_page > this.data_page_total) {
                                this.setData({
                                    data_bottom_line_status: true
                                });
                            } else {
                                this.setData({
                                    data_bottom_line_status: false
                                });
                            }
                        } else {
                            this.setData({
                                data_list_loding_status: 0
                            });

                            if (this.data_page <= 1) {
                                this.setData({
                                    data_list: [],
                                    data_bottom_line_status: false
                                });
                            }
                        }
                    } else {
                        this.setData({
                            data_list_loding_status: 0
                        });
                        app.globalData.showToast(res.data.msg);
                    }
                },
                fail: () => {
                    uni.hideLoading();
                    uni.stopPullDownRefresh();
                    this.setData({
                        data_list_loding_status: 2
                    });
                    app.globalData.showToast(this.$t('common.internet_error_tips'));
                }
            });
        },

        // 滚动加载
        scroll_lower(e) {
            this.get_data_list();
        }
    }
};
</script>
<style>
@import './list.css';
</style>
